package dai.ui

import android.view.View

abstract class UITween {

    var end = false  //  当前 end 结束
    var allEnd = false   // 整个tween链表结束
    var target: View? = null  // 指向下一个tween
    var nextTween: UITween? = null

    var headTween: UITween = this

    abstract fun execute(dt: Float)
    abstract fun clone(): UITween

    open fun initialize(node: View) {}

    fun runBy(pTarget: View, tweenModel: UITweenModel):UITween {
        val head = headTween
        head.target = pTarget
        tweenModel.tweenManager.addTween(head)
        return this
    }

}

//
fun UITween.cloneTween(): UITween {
    // tween 其实是一个链表
    val newHead: UITween = headTween.clone()
    var newCur = newHead
    var cur = headTween.nextTween
    var tmpTween: UITween
    while (cur != null) {
        tmpTween = cur.clone()
        newCur.nextTween = tmpTween
        newCur.headTween = newHead
        newCur = tmpTween
        cur = cur.nextTween
    }
    return newHead
}